import { defineStore } from 'pinia'  // 开创一个可以使用的仓库
import { ref } from 'vue'
const useImageStore = defineStore('ImageStore', () => {
    // 状态定义
    const uploadedImage = ref(null)
    const originalFile = ref(null)
    const analysisResult = ref(null)

    // 操作方法
    const uploadImage = (file) => {
        originalFile.value = file
        uploadedImage.value = URL.createObjectURL(file)
    }

    const setAnalysisResult = (result) => {
        analysisResult.value = result
    }

    const clearData = () => {
        // 显式释放 Blob 资源
        if (uploadedImage.value?.startsWith('blob:')) {
            URL.revokeObjectURL(uploadedImage.value)
        }
        // 手动重置状态（替代 $reset）
        uploadedImage.value = null
        originalFile.value = null
        analysisResult.value = null
    }
    return {
        uploadedImage,
        originalFile,
        analysisResult,
        uploadImage,
        setAnalysisResult,
        clearData
    }
})

export default useImageStore